require 'rubygems'
require 'hpricot'
require 'open-uri'

url = 'http://www3.lrs.lt/pls/inter/'
doc = Hpricot(open('http://www3.lrs.lt/pls/inter/w5_vaizdas.home?p_kat=103187').read)
img_url = (doc/"//a[@href ^= 'w5_vaizdas.nuotrauka' and position()]").first.attributes['href']
img_page = Hpricot(open(url+img_url).read)
img = (img_page/"//img[@src *= 'ImageData']").first
puts img.attributes['src']
puts img.attributes['alt']
f = File.new('dienos_nuotrauka.txt', 'w') 
f << img.attributes['src'] + "\n"
f << url+img_url + "\n"
f << img.attributes['alt'] + "\n"

